<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#btnExport").click(function(){
				top.$.jBox.confirm("确认要导出用户数据吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/userinfo/userInfo/export");
						$("#searchForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
    <!-- Bootstrap Admin Theme -->
    <link rel="stylesheet"  href="css/bootstrap-admin-theme.css">
    <link rel="stylesheet"  href="css/bootstrap-admin-theme-change-size.css">	
	<link href="${ctxStatic}/bootstrap/3.3.1/vendors/bootstrap-switch/build/css/bootstrap3/bootstrap-switch.min.css" type="text/css" rel="stylesheet" />
	<link href="${ctxStatic}/bootstrap/3.3.1/css/bootstrap-switch-small.css" rel="stylesheet">
	<link href="${ctxStatic}/bootstrap/3.3.1/css/bootstrap-theme-switch.min.css" rel="stylesheet">
	<script type="text/javascript" src="${ctxStatic}/bootstrap/3.3.1/vendors/bootstrap-switch/build/js/bootstrap-switch.min.js"></script>
    <script type="text/javascript">
         $(function() {
         	$('#mySwitch input').bootstrapSwitch();  
          	$('#mySwitch').on('switch-change', function (e, data) {
          		loading("修改状态");		
         	    var $el = $(data.el);
         	    var usertype = 0;
         	    value = data.value;
         	    //普通用户
			   	if(value==true)
			   		usertype = 1;
			   	else //专业用户
			   		usertype = 0;
         	   	var userid = $el.context.id;
	   			$.ajax({
					url : "${ctx}/userinfo/userInfo/updateStat",
					data:{"userid":""+userid,"usertype":+usertype},
					type:'post',
					cache:false,
					dataType:'json',
					success:function(data){
						closeLoading();			
					},
					error:function(){
						closeLoading();		
					}
				});	        	   
         	   //console.log(e, $el, value);
         	}); 
         });

    </script>	
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="">用户信息列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="userInfo" action="${ctx}/userinfo/userInfo/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>用户名：</label>
				<form:input path="username" htmlEscape="false" maxlength="20" class="input-medium"/>
			</li>
			<li><label>地区：</label>
				<sys:treeselect id="area" name="area.id" value="${userInfo.area.id}" labelName="area.name" labelValue="${userInfo.area.name}"
					title="区域" url="/sys/area/treeData" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
			</li>
			<li class="clearfix"></li>
			<li><label>姓名：</label>
				<form:input path="name" htmlEscape="false" maxlength="60" class="input-medium"/>
			</li>
			<li><label>用户类型：</label>
				<form:select path="userType" class="input-xlarge" style="width:90px">
					<form:option value="" label="请选择"/>
					<form:options items="${fns:getDictList('user_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>				
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="clearfix">
			<input id="btnExport" class="btn btn-primary" type="button" value="导出"/></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>用户名</th>
				<th>姓名</th>
				<th>地区</th>
				<th>民族</th>
				<th>创建日期</th>
				<shiro:hasPermission name="userinfo:userInfo:edit"><th>设置专业用户</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="userInfo">
			<tr>
				<td>
					${userInfo.username}
				</td>
				<td>
					${userInfo.name}
				</td>
				<td>
					${userInfo.area.name}
				</td>
				<td>
					${fns:getDictLabel(userInfo.nationType, 'nation_type', '无')}
				</td>
				<td>
					<fmt:formatDate value="${userInfo.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<shiro:hasPermission name="userinfo:userInfo:edit">
					<td>				
 						<div class="switch switch-small" id="mySwitch">
						    <input type="checkbox" <c:if test="${userInfo.userType == 1}">checked</c:if>  data-on-label="专业" data-off-label="普通" id="${userInfo.id}">
						</div>
					</td>
				</shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>

</html>